<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | SAPID CMS                               		  					  |
// +----------------------------------------------------------------------+
// | Author:  Dmitry Sheiko (www.cmsdevelopment.com)	                  |
// | Copyright (c) 2004 Dmitry Sheiko	                                  |
// | http://sapid.sourceforge.net	                                      |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// Release: 08.11.04 (dd/mm/yy)
// $Id: edit_template.inc.php,v 1.2 2005/06/14 13:38:01 mephius Exp $

if($_GET["option"]=="edit_ddc" OR $_GET["option"]=="create_ddc") {
	$lang["valuetitle1"] = $lang["expvaluetitle1"];
	$lang["sdctitle1"] = $lang["expsdctitle1"];
	$lang["ddctitle1"] = $lang["expddctitle1"];
	$lang["qctitle1"] = $lang["expqctitle1"];
}

$close = '<img src="'.$http_path.'usr/system/images/close.gif"  width="12" height="14" style="float: right" alt="'.$lang["Close"].'" border="0" />';
$panel = '
<script>
function storeCaret (textEl) {
if (textEl.createTextRange) 
textEl.caretPos = document.selection.createRange().duplicate();
}
function insertAtCaret (textEl, text) {
if (textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
caretPos.text =
caretPos.text.charAt(caretPos.text.length - 1) == \' \' ?
text + \' \' : text;
}
else
textEl.value = text;
}

// Inserting varibles
function insvalue(val) { 
	var html = document.getElementById(\'html\'); 
	insertAtCaret(html, \'<sapi:apply name="\'+val+\'.value" />\'); document.getElementById(\'svalue\').style.display=\'none\';
}
// Inserting ddc
function insddc(val) { 
	var html = document.getElementById(\'html\'); 
	insertAtCaret(html, \'<sapi:apply name="ddc.\'+val+\'.value" />\'); document.getElementById(\'ddc\').style.display=\'none\';
}
</script>



<!-- EXP inserting form -->
<div id="exp" style="z-index : auto; position : absolute; left : 50px; top : 260px; width: 400px; padding: 5px 5px 5px 5px; background-color: #CEE4F2; font-family: Tahoma, Arial; font-size: 11px; border: solid #5DB1EF 1px; display: none">
<a style="cursor: pointer;" onclick="document.getElementById(\'exp\').style.display=\'none\';" >'.$close.'</a>
<p align="center"><b>'.$lang["exptitle1"].'</b></p>
<p align="left"><i>'.$lang["exptitle2"].'</i></p>

<table height="100%" width="100%" cellpadding="0" cellspacing="0" style="font-family: Tahoma, Arial; font-size: 11px;">
	<tr>
		<td>
		'.$lang["Operands"].'
		</td>
		<td>
		<select onChange="document.getElementById(\'expvalue\').innerHTML=this.value" style="width: 200px; font-family: Tahoma, Arial; font-size: 11px;" name="exptype" id="exptype">
			<option value=""></option>
			<option value="lt(A.value , B.value)"> '.$lang["lt"].' </option>
			<option value="geq(A.value, B.value)"> '.$lang["geq"].' </option>
			<option value="eq(A.value, B.value)"> '.$lang["eq"].' </option>
			<option value="neq(A.value, B.value)"> '.$lang["neq"].' </option>
			<option value="gt(A.value, B.value)"> '.$lang["gt"].' </option>

			<option value="add(A.value, B.value)"> '.$lang["_add"].' </option>
			<option value="subtract(A.value, B.value)"> '.$lang["_subtract"].' </option>
			<option value="multiply(A.value, B.value)"> '.$lang["multiply"].' </option>
			<option value="divide(A.value, B.value)"> '.$lang["divide"].' </option>
		</select>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center" style="padding: 5px 5px 5px 5px">
		<div style="color: Gray" id="expvalue"></div>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center" style="padding: 10px 5px 5px 5px">
		<input type="button" onclick="var html = getElementById(\'html\'); insertAtCaret(html, document.getElementById(\'exptype\').value); document.getElementById(\'exptype\').value=\'\'; document.getElementById(\'exp\').style.display=\'none\'; " class="sapidcms_cont_btn" name="insertexp" value="'.$lang["exptitle1"].'">
		</td>
	</tr>
	
</table>

</div>


<!-- QC inserting form -->
<div id="qc" style="z-index : auto; position : absolute; left : 50px; top : 260px; width: 400px; padding: 5px 5px 5px 5px; background-color: #CEE4F2; font-family: Tahoma, Arial; font-size: 11px; border: solid #5DB1EF 1px; display: none">
<a style="cursor: pointer;" onclick="document.getElementById(\'qc\').style.display=\'none\';" >'.$close.'</a>
<p align="center"><b>'.$lang["qctitle1"].'</b></p>
<p align="left"><i>'.$lang["qctitle2"].'</i></p>

<table height="100%" width="100%" cellpadding="0" cellspacing="0" style="font-family: Tahoma, Arial; font-size: 11px;">
	<tr>
		<td>
		'.$lang["enterqueryname"].'
		</td>
		<td>
		<input type="TEXT" ONKEYPRESS="if ( (event.keyCode >= 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 95)) event.returnValue = false;" style="width: 200px" name="qcname" id="qcname" value="" />
		</td>
	</tr>
	<tr>
		<td>
		'.$lang["enterquerytitle"].'
		</td>
		<td>
		<input type="TEXT" style="width: 200px" name="qctitle" id="qctitle" value="" />
		</td>
	</tr>

	<tr>
		<td>
		'.$lang["electquerytype"].'
		</td>
		<td>
		<select  style="width: 200px; font-family: Tahoma, Arial; font-size: 11px;" name="qctype" id="qctype">
			<option value="string">'.$lang["qc_text"].'</option>
			<option value="publication">'.$lang["qc_publication"].'</option>
			<option value="image">'.$lang["Image"].'</option>
			<option value="file">'.$lang["File"].'</option>
			<option value="checkbox">Checkbox</option>
		</select>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center" style="padding: 10px 5px 5px 5px">
		<input type="button" onclick="var html = getElementById(\'html\'); if(document.getElementById(\'qcname\').value.length>0) { insertAtCaret(html, \'<sapi:apply name=&#034;qc.\'+document.getElementById(\'qcname\').value+\'.value&#034 type=&#034\'+document.getElementById(\'qctype\').value+\'&#034 title=&#034;\'+document.getElementById(\'qctitle\').value+\'.&#034; />\'); document.getElementById(\'qcname\').value=\'\'; document.getElementById(\'qc\').style.display=\'none\'; } else alert(\''.$lang["NeedQueryName"].'\') " class="sapidcms_cont_btn" name="insertqc" value="'.$lang["insertpointer"].'">
		</td>
	</tr>
	
</table>

</div>


<!-- VALUE inserting form -->
<div id="svalue" style="z-index : auto; position : absolute; left : 50px; top : 200px; width: 250px; padding: 5px 5px 5px 5px; background-color: #CEE4F2; font-family: Tahoma, Arial; font-size: 11px; border: solid #5DB1EF 1px; display: none">
<a style="cursor: pointer;" onclick="document.getElementById(\'svalue\').style.display=\'none\';" >'.$close.'</a>
<p align="center"><b>'.$lang["valuetitle1"].'</b></p>
<p align="left">
<i>'.$lang["valuetitle2"].'</i><br /><br />
<a style="cursor: pointer;" onclick="insvalue( \'http_path\')">'.$lang["http_path"].'</a><br />

<a style="cursor: pointer;" onclick="insvalue( \'document.title\')">'.$lang["this.title"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'document.id\')">'.$lang["this.id"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'document.variable\');">'.$lang["this.variable"].'</a><br />

<a style="cursor: pointer;" onclick="insvalue( \'argv_string\')">'.$lang["argv_string"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'last_argv\')">'.$lang["last_argv"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'len_argv\')">'.$lang["len_argv"].'</a><br />

<a style="cursor: pointer;" onclick="insvalue( \'argv.1\')">'.$lang["argv.1"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'document.level\');">'.$lang["document.level"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'document.template\');">'.$lang["document.template"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'document.datetime\');">'.$lang["document.datetime"].'</a><br />

<a style="cursor: pointer;" onclick="insvalue( \'page.pRead\')">'.$lang["page.pRead"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'page.pWrite\')">'.$lang["page.pWrite"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'page.pCreate\')">'.$lang["page.pCreate"].'</a><br />

<a style="cursor: pointer;" onclick="insvalue( \'user.LOGIN\')">'.$lang["user.LOGIN"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'user.GROUP\')">'.$lang["user.GROUP"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'user.aStatus\')">'.$lang["user.aStatus"].'</a><br />

<a style="cursor: pointer;" onclick="insvalue( \'default_charset\')">'.$lang["default_charset"].'</a><br />
<a style="cursor: pointer;" onclick="insvalue( \'default_language\')">'.$lang["default_language"].'</a><br />

</p>
</div>


<!-- VALUE inserting form -->
<div id="ddc" style="z-index : auto; position : absolute; left : 50px; top : 160px; width: 250px; padding: 5px 5px 5px 5px; background-color: #CEE4F2; font-family: Tahoma, Arial; font-size: 11px; border: solid #5DB1EF 1px; display: none">
<a style="cursor: pointer;" onclick="document.getElementById(\'ddc\').style.display=\'none\';" >'.$close.'</a>
<p align="center"><b>'.$lang["ddctitle1"].'</b></p>
<p align="left"><i>'.$lang["ddctitle2"].'</i> <br /><br />';


	$d = dir($root_path."usr/xml/ddc/");
	while($entry=$d->read()) {
		if(strlen($entry)>2 AND preg_match("/\.xml$/", $entry)) {
			$ddcname = preg_replace("/\.xml$/", "", $entry);
	    	$panel .= '<a style="cursor: pointer;" onclick="insddc(\''.$ddcname.'\')">'.$ddcname.'</a><br />';
		}
	}
	$d->close();

$panel .= '
</p>
</div>


<!-- SDC inserting form -->
<div id="sdc" style="z-index : auto; position : absolute; left : 50px; top : 260px; width: 400px; padding: 5px 5px 5px 5px; background-color: #CEE4F2; font-family: Tahoma, Arial; font-size: 11px; border: solid #5DB1EF 1px; display: none">
<a style="cursor: pointer;" onclick="document.getElementById(\'sdc\').style.display=\'none\';" >'.$close.'</a>
<p align="center"><b>'.$lang["sdctitle1"].'</b></p>
<p align="left"><i>'.$lang["sdctitle2"].'</i></p>

<table height="100%" width="100%" cellpadding="0" cellspacing="0" style="font-family: Tahoma, Arial; font-size: 11px;">
	<tr>
		<td>
		'.$lang["enterqueryname"].' 
		</td>
		<td>
		<input type="TEXT" ONKEYPRESS="if ( (event.keyCode >= 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 95)) event.returnValue = false;" style="width: 200px" name="sdcname" id="sdcname" value="" />
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center" style="padding: 10px 5px 5px 5px">
		<input type="button" onclick="var html = getElementById(\'html\'); if(document.getElementById(\'sdcname\').value.length>0) { insertAtCaret(html, \'<sapi:apply name=&#034;sdc.\'+document.getElementById(\'sdcname\').value+\'.value&#034 />\'); document.getElementById(\'sdcname\').value=\'\'; document.getElementById(\'sdc\').style.display=\'none\'; } else alert(\''.$lang["NeedQueryName"].'\') " class="sapidcms_cont_btn" name="insertsdc" value="'.$lang["insertpointer"].'">
		</td>
	</tr>
	
</table>

</div>';

$bottom_panel = '<table style="width: 100%; margin: 0px 5px 0px 5px;" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td nowrap="nowrap" valign="middle">
		<a style="cursor: pointer" onClick="if(document.getElementById(\'qc\').style.display==\'none\') document.getElementById(\'qc\').style.display=\'block\'; else document.getElementById(\'qc\').style.display=\'none\';"><img src="'.$http_path.'usr/system/images/addqc.gif"  width="22" height="14" style="margin-right: 2px" alt="'.$lang["qctitle1"].'" border="0" /></a>
		<a style="cursor: pointer" onClick="if(document.getElementById(\'sdc\').style.display==\'none\') document.getElementById(\'sdc\').style.display=\'block\'; else document.getElementById(\'sdc\').style.display=\'none\';"><img src="'.$http_path.'usr/system/images/addsdc.gif"  width="22" height="14" style="margin-right: 2px" alt="'.$lang["sdctitle1"].'" border="0" /></a>
		<a style="cursor: pointer" onClick="if(document.getElementById(\'ddc\').style.display==\'none\') document.getElementById(\'ddc\').style.display=\'block\'; else document.getElementById(\'ddc\').style.display=\'none\';"><img src="'.$http_path.'usr/system/images/addddc.gif"  width="22" height="14" style="margin-right: 2px" alt="'.$lang["ddctitle1"].'" border="0" /></a>
		<a style="cursor: pointer" onClick="if(document.getElementById(\'svalue\').style.display==\'none\') document.getElementById(\'svalue\').style.display=\'block\'; else document.getElementById(\'svalue\').style.display=\'none\';" ><img src="'.$http_path.'usr/system/images/addvalue.gif"  width="22" height="14" style="margin-right: 2px" alt="'.$lang["valuetitle1"].'" border="0" /></a>		
		'.(($_GET["option"]=="edit_ddc" OR $_GET["option"]=="create_ddc") ? '<a style="cursor: pointer" onClick="if(document.getElementById(\'exp\').style.display==\'none\') document.getElementById(\'exp\').style.display=\'block\'; else document.getElementById(\'exp\').style.display=\'none\';" ><img src="'.$http_path.'usr/system/images/addexp.gif"  width="22" height="14" style="margin-right: 2px" alt="'.$lang["exptitle1"].'" border="0" /></a>':'').'
		</td>
		<td align="right" valign="middle">
		<input type="submit" style="margin-right: 25px" class="sapidcms_cont_btn" name="savetemplate" value="'.$lang["savechanges"].'">
		</td>            
	</tr>
</table>';
?>